var pageNum=1,pageSize=9,pageTotal=0,total=0;

var rec_pay_minCon="",rec_pay_maxCon="",rec_workYearCon="",rec_company_addressCon="",rec_qualificationCon="",rec_dutyCon="";
$(function(){
	loadRecruitmentMmsg();
	
	$("#rec_pay_max").change(function(){
		//薪资小
		rec_pay_minCon = $("#rec_pay_min").val();
		if(rec_pay_minCon==""){rec_pay_minCon=0}
		//薪资大
		rec_pay_maxCon = $("#rec_pay_max").val();
		loadRecruitmentMmsg();
	});
	$("#rec_workYear").change(function(){
		//工作年限
		rec_workYearCon = $("#rec_workYear").val();
		loadRecruitmentMmsg();
	});
	$("#rec_company_address").change(function(){
		//工作地址
		rec_company_addressCon = $("#rec_company_address").val();
		loadRecruitmentMmsg();
	});
	$("#rec_qualification").change(function(){
		//工作学历
		rec_qualificationCon = $("#rec_qualification").val();
		loadRecruitmentMmsg();
	});
	
	$("#search_button").click(function(){
		//招聘岗位
		rec_dutyCon = $("#rec_duty").val();
		loadRecruitmentMmsg();
	});
	
	 //滚动监听
    $(window).scroll(function () {
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
       
        if (scrollTop + windowHeight >= scrollHeight) {
        	pageSize +=9;
        	$("#goLoad").text("加载中......");
        	$("#finishLoad").text("");
        	loadRecruitmentMmsg();
        }
    });
});

function loadRecruitmentMmsg(){
	utilAjax('/recruitment_msg/queryAllByRecruitment_msg',
			'pageNum='+pageNum+'&pageSize='+pageSize+'&rec_pay_min='+rec_pay_minCon+'&rec_pay_max='+rec_pay_maxCon+"&rec_workYear="+rec_workYearCon+"&rec_company_address="+rec_company_addressCon+"&rec_qualification="+rec_qualificationCon+"&rec_duty="+rec_dutyCon,
			'get',function(data){
		pageNum = data.pageNum;
		pageSize = data.pageSize;
		pageTotal = data.pages;
		total = data.total;
		parseRecruitmentMmsg(data.list);
	});
}

function parseRecruitmentMmsg(lists){
	$("#goLoad").text("");
	$("#finishLoad").text("");
	var recmsg = "";
	if(lists!=""){
		$.each(lists,function(i,r){
			var rec_workYear = "";//设置经验年限
			if(r.rec_workYear==1){rec_workYear = "在校生"}
			if(r.rec_workYear==2){rec_workYear = "应届生"}
			if(r.rec_workYear==3){rec_workYear = "一年以内"}
			if(r.rec_workYear==4){rec_workYear = "1-5年"}
			if(r.rec_workYear==5){rec_workYear = "5-10年"}
			if(r.rec_workYear==6){rec_workYear = "10年以上"}
			var rec_qualification = "";//设置学历要求
			if(r.rec_qualification==1){rec_qualification = "初中及以下"}
			if(r.rec_qualification==2){rec_qualification = "中专/技校"}
			if(r.rec_qualification==3){rec_qualification = "高中"}
			if(r.rec_qualification==4){rec_qualification = "大专"}
			if(r.rec_qualification==5){rec_qualification = "本科"}
			if(r.rec_qualification==6){rec_qualification = "硕士"}
			if(r.rec_qualification==7){rec_qualification = "博士"}
			recmsg += "<li onclick=lookNews("+r.rec_id+") class='position_list_item default_list position_hot_list_item'>"+
						"<div class='pli_top'>"+
						"<div class='clearfix pli_top_l'>"+
							"<div class='position_name fl  '>"+
								"<h2 class='dib clearfix'>"+
									"<a href='javascript:lookNews("+r.rec_id+")' class='position_link fl wordCut' title='"+r.rec_title+"'>"+r.rec_title+"</a>"+
								"</h2>"+
							"</div>"+
							"<span class='salary fr'>"+r.rec_pay_min+"-"+r.rec_pay_max+"</span>"+
						"</div>"+
						"<div class='position_main_info wordCut'>"+
							"<span>经验："+rec_workYear+"</span> <span>学历："+rec_qualification+"</span>"+
						"</div>"+
						"<div class='labels'>"+
							"<div class='pli_btm_l'>"+
								"<span class='wordCut' title='"+r.rec_duty+"'>"+r.rec_duty+"</span>"+
							"</div>"+
						"</div>"+
					"</div>"+
					"<div class='pli_btm clearfix'>"+
						"<a class='fl'>"+ 
							"<img src='/image/"+r.recruiter_basic.company_msg.company_img+"' alt='公司logo' " +
								"class='company-logo' width='40' height='40' target='_blank'>"+ 
						"</a>"+
						"<div class='bottom-right'>"+
							"<h3 class='company_name'>"+
								"<c>"+r.rec_company_name+"</c>"+
							"</h3>"+
							"<h3 class='industry wordCut'>"+
								"<span>招聘地址："+r.rec_company_address+"</span>"+
								"<span>招聘人："+r.recruiter_basic.recruiter_name+"</span>"+
							"</h3>"+
						"</div>"+
					"</div>"+
				"</li>";
		});
		if(lists.length==total){
			$("#goLoad").text("");
			$("#finishLoad").text("加载到底部了~~~");
		}
	}else{
		recmsg = "<center style='position:absolute;z-index:100;left:42%;'><font size='6' color='red'>暂无招聘信息</font></center>";
	}
	
	$("#recruitmentMmsg").html(recmsg);
}

function lookNews(rec_id){
	window.location.href="/recruitment_msg/queryByRec_id?rec_id="+rec_id;
}




function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}